 /*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mx.itschapala.dsw2.invernadero.BL;

import java.util.List;
import javax.ejb.EJB;
import javax.ejb.Stateless;
import mx.itschapala.dsw2.invernadero.Dao.StaffDaoLocal;
import mx.itschapala.dsw2.invernadero.Enumeracion.Estado;
import mx.itschapala.dsw2.invernadero.modelo.Staff;

/**
 *
 * @author Raven
 */
@Stateless
public class StaffBL implements StaffBLLocal {
    @EJB
    private StaffDaoLocal staffDao;

    @Override
    public Estado register(Staff staff){
           if (staffDao.findDuplicity(staff)) {
            return Estado.INCOMPLETE;
        } else {
            staffDao.create(staff);
            return Estado.COMPLETE;
        }
    }

    @Override
    public Estado modify(Staff staff) {
             if(staff.getIdstaff()==null || staffDao.find(staff.getIdstaff())==null){
       return Estado.INCOMPLETE;
    } else{
            staffDao.edit(staff);
            return Estado.COMPLETE;
        }
    }

    @Override
    public Estado delete(Staff staff) {
          if (staff.getIdstaff() != null || staffDao.find(staff.getIdstaff()) != null){
        staffDao.remove(staff);
            return Estado.COMPLETE;
        }else {
            return Estado.INCOMPLETE;
        }
    }

    @Override
    public List<Staff> getList() {
        return staffDao.findAll();
    }
    
      public Staff findById(Integer id) {
        return staffDao.find(id);
    }
      
      public Staff findName(String name)
      {
      return  staffDao.find(name);
      }
    

}
